package com.yonyou.cyxdms.sysAuth.service.controller.dealer;

import com.yonyou.cyx.framework.util.bean.ApplicationContextHelper;
import com.yonyou.cyxdms.framework.bean.dto.user_info.LoginInfoDto;
import com.yonyou.cyxdms.sysAuth.service.dto.dealer.MsgRecordDTO;
import com.yonyou.cyxdms.sysAuth.service.dto.dealer.MsgRecordNoticeDTO;
import com.yonyou.cyxdms.sysAuth.service.dto.dealer.MsgRecordNoticeVO;
import com.yonyou.cyxdms.sysAuth.service.service.dealerchannel.MsgRecordNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.yonyou.cyx.framework.controller.base.BaseController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author adu
 * @since 2019-10-11
 */
//@Api(value = "公告维护DLR", tags = {"公告维护Api"})
@RestController
@RequestMapping("/notice/msgRecordNotice")
public class MsgRecordNoticeController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(MsgRecordNoticeController.class);

    @Autowired
    public MsgRecordNoticeService msgRecordNoticeService;

    /**
     * 分页查询数据
     *
     * @param queryCondition 查询条件
     * @return com.baomidou.mybatisplus.core.metadata.IPage 分页对象
     * @author adu
     * @since 2019-10-11
     */
    @ResponseBody
    @GetMapping
    @ApiImplicitParams({
            @ApiImplicitParam(value = "员工id", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @ApiOperation(value = "查询-公告维护（分页）")
    public IPage<Map<String, Object>> getList(MsgRecordNoticeVO msgRecordNoticeVO, @RequestParam(value = "currentPage", defaultValue = "1") int currentPage, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
        Page<Map<String, Object>> page = new Page(currentPage, pageSize);
        LoginInfoDto loginInfoDto = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
        Map<String, Object> queryCondition = new HashMap<>();
        queryCondition.put("appId", loginInfoDto.getAppId());
        queryCondition.put("noticeType", msgRecordNoticeVO.getNoticeType());
        queryCondition.put("noticeTitle", msgRecordNoticeVO.getNoticeTitle());
        queryCondition.put("noticePublisher", msgRecordNoticeVO.getNoticePublisher());
        queryCondition.put("peleaseStatus", msgRecordNoticeVO.getPeleaseStatus());
        queryCondition.put("effectivTime", msgRecordNoticeVO.getEffectivTime());
        queryCondition.put("effectivTime2", msgRecordNoticeVO.getEffectivTime2());
        queryCondition.put("releaseTime", msgRecordNoticeVO.getReleaseTime());
        queryCondition.put("releaseTime2", msgRecordNoticeVO.getReleaseTime2());
        return msgRecordNoticeService.selectPageByNotice(page, queryCondition);
    }

    /**
     * 进行数据新增
     *
     * @param msgRecordNoticeDTO 需要保存的DTO
     * @return Map<String, Object> 返回的数据map
     * @author adu
     * @since 2019-10-11
     */
    @ResponseBody
    @PostMapping
    @ApiImplicitParams({
            @ApiImplicitParam(value = "员工id", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @ApiOperation(value = "新增-公告维护（直接发布）")
    public Integer insert(@RequestBody MsgRecordNoticeDTO msgRecordNoticeDTO) {
        logger.debug("msgRecordNoticeDTO:{}", msgRecordNoticeDTO);
        return msgRecordNoticeService.addNotice(msgRecordNoticeDTO);
    }

    /**
     * 编辑-公共维护-及发布
     */
    @ApiOperation(value = "编辑-公告维护-及发布")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "userId", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @PutMapping("/updateReleaseStatus/{noticeId}")
    public Map<String, Object> updateReleaseStatus(@PathVariable("noticeId") Integer noticeId, @RequestBody MsgRecordNoticeDTO msgRecordNoticeDTO) {
        return msgRecordNoticeService.updateReleaseStatus(noticeId, msgRecordNoticeDTO);
    }


    /**
     * 经销商角色属性（新增）
     */


    /**
     * 已读列表（用户名、员工姓名、首次阅读时间）
     */

    /**
     * 未读列表（用户名、员工姓名）
     */


    /**
     * 进行数据修改
     *
     * @param id 数据主键ID
     * @return Map<String, Object> 数据对应的map 结构
     * @author adu
     * @since 2019-10-11
     */
  /*  @ResponseBody
    @GetMapping(value = "/{id}")
    @SuppressWarnings("unchecked")
    public Map<String, Object> getById(@PathVariable("id") Long id) {
        return msgRecordNoticeService.getById(id);
    }
*/


    /**
     * 进行数据修改
     *
     * @param id                 需要修改数据的ID
     * @param msgRecordNoticeDTO 需要保存的DTO
     * @return Map<String, Object> 返回的数据map
     * @author adu
     * @since 2019-10-11
     */
/*    @ResponseBody
    @PutMapping(value = "/{id}")
    @ResponseStatus(HttpStatus.CREATED)
    @SuppressWarnings("unchecked")
    public Map<String, Object> update(@PathVariable("id") Long id, @RequestBody MsgRecordNoticeDTO msgRecordNoticeDTO) {
        logger.debug("msgRecordNoticeDTO:{}", msgRecordNoticeDTO);
        return msgRecordNoticeService.update(id, msgRecordNoticeDTO);
    }*/

    /**
     * 根据id删除对象
     *
     * @param id 需要修改数据的ID
     * @author adu
     * @since 2019-10-11
     */
/*    @DeleteMapping(value = "/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public boolean deleteById(@PathVariable("id") Long id) {
        logger.debug("删除ID:{}", id);
        msgRecordNoticeService.deleteById(id);
        return true;
    }*/

    /**
     * 根据IDs批量删除对象
     *
     * @param ids 需要修改数据的ID集合
     * @author adu
     * @since 2019-10-11
     */
/*    @DeleteMapping(value = "/batch/{ids}")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public boolean deleteByIds(@PathVariable("ids") String ids) {
        logger.debug("删除ID:{}", ids);
        msgRecordNoticeService.deleteBatchIds(ids);
        return true;
    }*/


}